<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:ui="http://java.sun.com/jsf/facelets">


<body>
<ui:composition template="/template2.xhtml">
	<ui:define name="titulo">Listar Motorista</ui:define>
	<ui:define name="barra_titulo">Listar Motoristas</ui:define>
	<ui:define name="corpo">
			
			<p:messages>
			</p:messages>
	
			<h:form id="formListar">
				<p:dataTable var="motorista"
					value="#{motoristaBean.motoristas}" selection="#{motoristaBean.motorista }" update="display" selectionMode="single" emptyMessage="Motoristas não Cadastrados" rowKey="#{motorista.nome}">
					 
					 <p:ajax event="rowSelect"   
                   		 update=":formAlterar:infoAlt" oncomplete="dialogo.show()" />
					
					<p:column>
						<f:facet name="header">
							<h:outputText value="Nome:" />
						</f:facet>
						<h:outputText value="#{motorista.nome}" />
					</p:column>
					<p:column>
						<f:facet name="header">
							<h:outputText value="Cidade:" />
						</f:facet>
						<h:outputText value="#{motorista.cidade}" />
					</p:column>
					
					<p:column>
						<f:facet name="header">
							<h:outputText value="UF:" />
						</f:facet>
						<h:outputText value="#{motorista.uf}" />
					</p:column>
					<p:column>
						<f:facet name="header">
							<h:outputText value="Telefone:" />
						</f:facet>
						<h:outputText value="#{motorista.uf}" />
					</p:column>
					<p:column>
						<f:facet name="header">
							<h:outputText value="cpf" />
						</f:facet>
						<h:outputText value="#{motorista.cpf}" />
					</p:column>
					<p:column>
						<p:commandLink type="button" oncomplete="cd.show()" update=":dlg">
							<h:graphicImage alt="Excluir Registro" library="imagens" name="delete.png"
								styleClass="image"></h:graphicImage>
							<f:setPropertyActionListener target="#{motoristaBean.motorista}"
								value="#{motorista}" />
						</p:commandLink>
					</p:column>
				</p:dataTable>
			</h:form>
				
				<h:form id="dlg">
					<p:confirmDialog message="Deseja realmente excluir o motorista: #{motoristaBean.motorista.nome}?"
						hideEffect="explode" header="Excluir" severity="alert" widgetVar="cd">
						<p:commandButton value="Sim" actionListener="#{motoristaBean.excluir}"
							update=":formListar" oncomplete="cd.hide()" />
						<p:commandButton value="Não" onclick="cd.hide()" type="button" />
					</p:confirmDialog>
				</h:form>

			<p:dialog header="Editar Motorista" widgetVar="dialogo" width="400"
				modal="true" resizable="false" closable="false">
				<p:outputPanel id="display">
					<h:form id="formAlterar">
						<h:panelGrid columns="2" id="infoAlt">
							<h:outputLabel value="Nome" />
							<p:inputText value="#{motoristaBean.motorista.nome}" />
							<h:outputLabel value="Endereço:" />
							<p:inputText value="#{motoristaBean.motorista.endereco}" />
							<h:outputLabel value="Cidade:" />
							<p:inputText value="#{motoristaBean.motorista.cidade}" />
							<h:outputLabel value=" UF:" />
							<p:inputText size="2" value="#{motoristaBean.motorista.uf}" />
							<h:outputLabel value="Telefone:" />
							<p:inputMask value="#{motoristaBean.motorista.telefone}"
								mask="(99) 9999-9999" />
							<h:outputLabel value="CPF:" />
							<p:inputMask size="12" value="#{motoristaBean.motorista.cpf}"
								mask="999.999.999-99" />

						</h:panelGrid>
						<br />
						<p:commandButton action="#{motoristaBean.editar}" value="Salvar"
							update=":formListar" oncomplete="dialogo.hide()" />
						<p:commandButton value="Cancelar"
							action="#{motoristaBean.cancelaEditar}"
							oncomplete="dialogo.hide()" />
					</h:form>
				</p:outputPanel>
			</p:dialog>

		</ui:define>
		</ui:composition>		
</body>
</html>
